import axios from 'axios'
import { TypeUrl } from '@/utils/url.js'
export default {
    namespaced: true,
    state: {
        list: []
    },
    mutations: {
        setList(state, data) {
            state.list = data
        }
    },
    actions: {
        get({ commit }) {
            return new Promise((rs, rj) => {
                axios({
                    url: TypeUrl,
                    method: "get",
                    params: {
                        transform: 1
                    }
                }).then(res => {
                    commit('setList', res.data.classify)
                    rs(res)
                }).catch(e => {
                    rj(e)
                })
            })
        },
        save({ commit }, obj) {
            return new Promise((rs, rj) => {
                axios({
                    url: TypeUrl,
                    method: "post",
                    data: obj
                }).then(res => {
                    rs()
                }).catch(e => {
                    rj(e)
                })
            })
        }
    }
}